<template>
  <div>
    <el-row :gutter="20" style="margin-bottom: 20px">
          <el-input v-model="name" placeholder="请输入租户名"></el-input>
          <el-input v-model="accessKey" placeholder="请输入租户Key"></el-input>
          <el-button type="primary" @click.prevent="fnLoadData(1)">查询</el-button>
          <el-button type="danger"  @click.prevent="fnRestFrom">
            <i class="el-icon-refresh-left" ></i>清空
          </el-button>

    </el-row>
    <el-table
        :data="bean.list"
        border
        with="700px"
        style="text-align: center">
      <el-table-column
          fixed
          prop="name"
          label="租户名"
          :with="78">
      </el-table-column>
      <el-table-column
          prop="accessKey"
          label="租户key"
          :with="177">
      </el-table-column>
      <el-table-column
          prop="companyName"
          label="公司名称"
          :with="204">
      </el-table-column>
      <el-table-column
          prop="companyCode"
          label="执照编号"
          :with="85">
      </el-table-column>
      <el-table-column
          prop="phone"
          label="手机号"
          :with="110">
      </el-table-column>
      <el-table-column
          prop="enable"
          label="是否可用"
          :with="84">
      </el-table-column>
      <el-table-column
          prop="description"
          label="描述"
          :with="157">
      </el-table-column>
      <el-table-column
          prop="auditStatus"
          label="状态"
          :with="84">
        <template slot-scope="{row}">
          <span v-if="row.auditStatus === 0"><el-tag type="danger">待审核</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column
          label="操作"
          :with="62">
        <template slot-scope="scope">
          <el-button  @click="fnPreUpdate(scope.row)" type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        @current-change="fnLoadData"
        :current-page.sync="page"
        :page-size="bean.pageSize"
        :total="bean.total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "TenantManageView",
  methods: {
    fnSearch(){
      this.fnLoadData();
    },
    fnAdd(){

    },
    fnPreUpdate(){

    },
    fnLoadData(p){
      this.page = p;
      this.axios.get("http://localhost:8080/tenants/tenantsList", {
        params: {
          auditStatus:0,
          name:this.name,
          accessKey:this.accessKey,
          page:this.page }})
          .then(res=>{
            console.log(res)
            if (res.data.code === "200"){
              this.$message.success("查询成功");
              this.bean = res.data.data;
            }
          });
    },
    fnRestFrom(p){
      this.axios.get("http://localhost:8080/tenants/tenantsList", {params: { p } })
          .then(res=>{
            console.log(res)
            if (res.data.code === "200"){
              this.$message.success("查询成功");
              this.bean = res.data.data;
            }
          });
    }
  },

  data() {
    return {
      bean:{
        list:[]
      },
      page:1,
      accessKey:'',
      name:'',
      userInfo:{}
    }
  },
  mounted() {
    this.fnLoadData();
    var u = sessionStorage.getItem("userInfo");
    if (u){
      this.userInfo = JSON.parse(u);
    }
  }
}
</script>

<style scoped>
.el-row {
  display: flex;
  align-items: center;
}

.el-input {
  margin-right: 10px;
  width:150px;
}

.el-button {
  margin-right: 10px;
}
</style>
